﻿using System.Collections.Generic;
using MagicWorld.DDD.Domain.Entity;
using MagicWorld.DDD.Domain.Service.DamagePolicy.Impl;

namespace MagicWorld.DDD.Domain.Service.DamagePolicy
{
    public class DamageManager
    {
        private static readonly List<IDamagePolicy> POLICIES = new List<IDamagePolicy>();

        static DamageManager()
        {
            POLICIES.Add(new DragoonPolicy());
            POLICIES.Add(new DragonImmunityPolicy());
            POLICIES.Add(new OrcResistancePolicy());
            POLICIES.Add(new ElfResistancePolicy());
            POLICIES.Add(new PhysicalDamagePolicy());
            POLICIES.Add(new DefaultDamagePolicy());
        }

        /// <summary>
        /// 计算伤害
        /// </summary>
        /// <returns></returns>
        public long CalculateDamage(Player player, Weapon weapon, Monster monster)
        {
            foreach (var policy in POLICIES)
            {
                if (!policy.CanApply(player, weapon, monster))
                {
                    continue;
                }
                return policy.CalculateDamage(player, weapon, monster);
            }
            return 0;
        }
    }
}